﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class News_GuestBookAdd : System.Web.UI.Page
{
    PM.PMSys.guestbook aguestbook = new PM.PMSys.guestbook();
    protected void Page_Load(object sender, EventArgs e)
    {
        Loadsys();
    }
    protected void Loadsys() 
    {
        if (Session["name"]!=null)
        {
            txtUserName.Text = Session["name"].ToString();
        } 
    }
    protected void ddlPic_SelectedIndexChanged(object sender, EventArgs e)
    {
        Image1.ImageUrl = "../images/face/" + ddlPic.SelectedValue.ToString();
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (txtContent.Text.Length > 600)
        {
            lblWorning.Text="留言的字数太多，请适当删减！";
            return;
        }
        else if (txtContent.Text.Length<10)
        {
            lblWorning.Text="留言的字数太少，请适当修改！";
            return;
        }
        else
        {
            string name = string.Empty;
            string email = string.Empty;
            string qq = string.Empty;
            string picurl = string.Empty;
            string comment = string.Empty;
            name = txtUserName.Text.Trim() == "" ? Request.UserHostAddress : txtUserName.Text.Trim();
            email = txtEmail.Text.Trim() == "" ? "保密" : txtEmail.Text.Trim();
            qq = txtQq.Text.Trim() == "" ? "保密" : txtQq.Text.Trim();
            picurl = ddlPic.SelectedValue.ToString();
            comment = txtContent.Text;
            bool result = aguestbook.AddComment(name, email, qq, picurl, comment);
            if (result)
            {
                PM.Code.Web.alertmessage.ShowMsg("留言成功，管理员审核通过后才能显示！","GuestBook.aspx");
            }
            else
            {
                PM.Code.Web.alertmessage.ShowMsg("留言失败，请重试！");
            }
        }
    }
}
